package com.ruoyi.app.controller.member.mapper;

import com.ruoyi.common.core.dao.BaseMapper;
import com.ruoyi.common.entity.DO.member.MemberVipBenefitDO;
import com.ruoyi.common.entity.DO.member.MemberVipTypeDO;
import com.ruoyi.common.entity.VO.member.MemberVipBenefitVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IMemberVipBenefitMapper extends BaseMapper<MemberVipBenefitDO> {

    @Select("SELECT * FROM member_vip_benefit m left join product p ON m.product_id = p.id WHERE p.is_enbale=1 and p.is_delete=0 and m.is_enable=1 and m.is_delete=0")
    List<MemberVipBenefitDO> searchList();

    @Select("SELECT is_credit isCredit,is_discount isDiscount,benefit_credit benefitCredit,benefit_credit_rate benefitCreditRate,benefit_discount_reduce benefitDiscountReduce,benefit_discount_rate benefitDiscountRate,m.system_module systemModule," +
            " p.product_name productName,p.buy_unit buyUnit,p.product_category productCategoryName,sp.product_price price" +
            " FROM member_vip_benefit m" +
            " left join shop_product sp ON m.product_id = sp.product_id" +
            " left join product p ON m.product_id = p.id" +
            " WHERE m.shop_id=#{shopId} and sp.shop_id=#{shopId} and p.is_enable=1 and p.is_delete=0 and m.is_enable=1 and m.is_delete=0 and m.member_vip_type_id=#{vipTypeId}")
    List<MemberVipBenefitVO> searchListByVipTypeId(@Param("vipTypeId") Long vipTypeId, @Param("shopId") Long shopId);

    @Select("SELECT is_credit isCredit,is_discount isDiscount,benefit_credit benefitCredit,benefit_credit_rate benefitCreditRate,benefit_discount_reduce benefitDiscountReduce,benefit_discount_rate benefitDiscountRate,m.system_module systemModule," +
            " p.product_name productName,p.buy_unit buyUnit,p.product_category productCategoryName,sp.product_price price" +
            " FROM member_vip_benefit m" +
            " left join shop_product sp ON m.product_id = sp.product_id" +
            " left join product p ON m.product_id = p.id" +
            " WHERE m.shop_id=#{shopId} and sp.shop_id=#{shopId} and m.product_id=#{productId} and p.is_enable=1 and p.is_delete=0 and m.is_enable=1 and m.is_delete=0 and m.member_vip_type_id=#{vipTypeId}")
    MemberVipBenefitVO getBenefitInfoByProductId(@Param("vipTypeId") Long vipTypeId, @Param("shopId") Long shopId, @Param("productId") Long productId);
}
